package com.hsq.end_of_period;

public class ShapeArea {
    public static void main(String[] args) {
        MyRectangle r = new MyRectangle(2, 5);
        System.out.println(r);
        MyTriangle t = new MyTriangle(3, 4, 5);
        System.out.println(t);
    }
}

interface ShapeArea1{
    double getArea();
    double getPerimeter();
}

class MyRectangle implements ShapeArea1 {
    double w;
    double h;

    MyRectangle(double w, double h) {
        this.w = w;
        this.h = h;
    }
    @Override
    public double getArea() {
        return w * h;
    }

    @Override
    public double getPerimeter() {
        return 2 * (w + h);
    }

    @Override
    public String toString() {
        return "width=" + w + ",height=" + h + ",perimeter=" + this.getPerimeter() + "area=" + getArea();
    }
}

class MyTriangle implements ShapeArea1{
    double a, b, c, s;

    public MyTriangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.s = (a + b + c) / 2;
    }

    @Override
    public double getArea() {
        return Math.sqrt(s * (s - a) * (s - b) * (s -c));
    }

    @Override
    public double getPerimeter() {
        return a + b + c;
    }

    @Override
    public String toString() {
        return "three sides:" + a + "," + b + "," + c + ",perimeter=" + getPerimeter() + ",area=" + getArea();
    }
}
